package cn.edu.nju.askinginhand.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
/**
 * 
 * @author ZhangZu
 *
 */
public class AnswerHistoryActivity extends Activity {
	TextView answerHistoryText;
	ListView answerHistoryList;
	List<Map<String, Object>> list;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.answer_history);
		answerHistoryText = (TextView) findViewById(R.id.answerHistoryText);
		answerHistoryList = (ListView) findViewById(R.id.answerHistoryList);

		initHistoryList();
	}

	public void initHistoryList() {
		SimpleAdapter expAdapter = new SimpleAdapter(
				AnswerHistoryActivity.this, getData(),
				R.layout.answer_history_item, new String[] { "quesTitle",
						"answerTime" }, new int[] { R.id.quesTitleText,
						R.id.answerTimeText });
		answerHistoryList.setAdapter(expAdapter);

		answerHistoryList.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View v, int pos,
					long id) {
				String strId = (Integer) list.get(pos).get("quesId") + "";
				Toast.makeText(AnswerHistoryActivity.this, strId,
						Toast.LENGTH_SHORT).show();
				Bundle bundle = new Bundle();
				bundle.putString("id", strId);
				/*
				 * Intent intent = new Intent(QuesHistoryActivity.this,
				 * CheckQues.class); intent.putExtras(bundle);
				 * startActivity(intent);
				 */
			}
		});
	}

	private List<Map<String, Object>> getData() {
		list = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < 2; i++) {
			Map<String, Object> ques = new HashMap<String, Object>();
			ques.put("quesId", i);// replace i by Real Id here
			ques.put("quesTitle", "textTitle");
			ques.put("answerTime", "2011/5/10");
			list.add(ques);
		}
		return list;
	}
}
